<?php
/**
 * @author sanketsp
 * Student class: Holds data on every student present in a group, belonging to a course.
 *
 */
class Student {
	/**
	 * Constructor
	 * @param $id ID of the Student
	 */
	function __construct($id) {
		$query = mysql_query("SELECT * FROM `student` WHERE `id` = '$id';") or die(mysql_error());
		$result = mysql_fetch_object($query);
		if($result) {
			foreach($result as $key=>$value) {
				$this->$key = $value;
			}
		}
	}
	/**
	 * Updates student data
	 */
	public function updateStudent() {
		$query = mysql_query("UPDATE `student` SET `full_name` = '$this->full_name', `email` = '$this->email', `group_id` = '$this->group_id', `visible` = '$this->visible' WHERE `id` = '$this->id'") or die(mysql_error());
		return true;
	}
	/**
	 * Gets count of all forum posts made by this student
	 */
	public function getForumCount(){
		$query = mysql_query("SELECT * FROM `forum` WHERE `author` = '$this->id'") or die(mysql_error());
		$count = mysql_num_rows($query);
		return $count;
	}
	/**
	 * Gets count of all SVN commits made by this student
	 */
	public function getSVNCount(){
		$query = mysql_query("SELECT * FROM `svn` WHERE `author` = '$this->id'") or die(mysql_error());
		$count = mysql_num_rows($query);
		return $count;
	}
	/**
	 * Gets count of all wiki posts made by this student
	 */
	public function getWikiCount(){
		$query = mysql_query("SELECT * FROM `wiki` WHERE `author` = '$this->id'") or die(mysql_error());
		$count = mysql_num_rows($query);
		return $count;
	}
	/**
	 * Gets count of all files added/modified by this student
	 */
	public function getFileCount(){
		$query = mysql_query("SELECT * FROM `file` WHERE `author` = '$this->id'") or die(mysql_error());
		$count = mysql_num_rows($query);
		return $count;
	}
	/**
	 * Gets count of all issues added/modified made by this student
	 */
	public function getIssueCount(){
		$query = mysql_query("SELECT * FROM `issue` WHERE `author` = '$this->id'") or die(mysql_error());
		$count = mysql_num_rows($query);
		return $count;
	}
}